// index.js

/**
 * 组件类型
 */
const PAGETYPE = {
  QRCODE: "QRCODE",
  FILE_UPLOADER: "FILE_UPLOADER",
  SHARE: "SHARE",
  WXML_TO_CANVAS: "WXML_TO_CANVAS",
  SWIPER: "SWIPER",
  VIDEO_SWIPER: "VIDEO_SWIPER",
  M_STICKY: "M_STICKY",
  POSTER: "POSTER",
};
/**
 * 全部路由
 */
const ROUTERS = {
  [PAGETYPE.QRCODE]: "/pages/qrcode/index",
  [PAGETYPE.FILE_UPLOADER]: "/pages/file-uploader/client/index/index",
  [PAGETYPE.SHARE]: "/pages/components/share/share",
  [PAGETYPE.WXML_TO_CANVAS]: "/pages/components/wxml-to-canvas/index",
  [PAGETYPE.SWIPER]: "/pages/components/swiper/swiper",
  [PAGETYPE.VIDEO_SWIPER]: "/pages/components/video-swiper/video-swiper",
  [PAGETYPE.M_STICKY]: "/pages/components/m-sticky/m-sticky",
};
/**
 * 列表展示
 */
const LIST = [
  { title: "生成二维码", type: PAGETYPE.QRCODE },
  { title: "文件上传", type: PAGETYPE.FILE_UPLOADER },
  { title: "分享", type: PAGETYPE.SHARE },
  { title: "Wxml to canvas", type: PAGETYPE.WXML_TO_CANVAS },
  { title: "轮播图", type: PAGETYPE.SWIPER },
  { title: "视频轮播", type: PAGETYPE.VIDEO_SWIPER },
  { title: "自定义滚动吸顶效果", type: PAGETYPE.M_STICKY },
];

// 获取应用实例
const app = getApp();

/**
 * 组件入口
 */

Page({
  data: {
    list: [],
  },
  onLoad() {
    this.setData({
      list: LIST,
    });
  },

  /**
   * 跳转页面
   */
  toPage(e) {
    const { type } = e.currentTarget.dataset;

    let url = "";
    for (const key in ROUTERS) {
      if (Object.hasOwnProperty.call(ROUTERS, type)) {
        url = ROUTERS[PAGETYPE[type]];
      }
    }

    wx.navigateTo({ url });
  },
});
